home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fscheck / fscheck.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-01  |  7.6 KB  |  279 lines

  1. /* 
  2.  * fscheck.h
  3.  *
  4.  *    Types for the file system check program.
  5.  *
  6.  * Copyright (C) 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  *
  9.  * $Header: /sprite/src/cmds/fscheck/RCS/fscheck.h,v 1.17 90/10/10 15:29:07 mendel Exp $ SPRITE (Berkeley)
  10.  */
  11.  
  12. #ifndef _FSCHECK
  13. #define _FSCHECK
  14.  
  15. #include "disk.h"
  16. #include <sys/types.h>
  17. #include <varargs.h>
  18. #include <stdio.h>
  19. #include <errno.h>
  20. #include <stdlib.h>
  21. #include <time.h>
  22. #include <sys/time.h>
  23.  
  24. /*
  25.  *  fscheck Proc_Exit status codes.
  26.  *     Codes < 0 are hard errors. Codes > 0 are soft errors.
  27.  *
  28.  */
  29. #define EXIT_OK        (char) 0
  30.  
  31. #define EXIT_SOFT_ERROR        (char) 1
  32. #define EXIT_OUT_OF_MEMORY    (char) 2
  33. #define EXIT_NOREBOOT        (char) 3
  34. #define EXIT_REBOOT        (char) 4
  35.  
  36. #define EXIT_HARD_ERROR        (char) -1
  37. #define EXIT_READ_FAILURE    (char) -2
  38. #define EXIT_WRITE_FAILURE    (char) -3
  39. #define EXIT_BAD_ARG        (char) -4
  40. #define EXIT_MORE_MEMORY    (char) -5
  41. #define EXIT_DISK_FULL        (char) -6
  42.  
  43. /*
  44.  * Structure kept for each file descriptor.
  45.  */
  46. typedef struct FdInfo {
  47.     short    flags;        /* Flags defined below. */
  48.     short    origLinkCount;    /* Link count from the file descriptor. */
  49.     short    newLinkCount;    /* Link computed by checkFS. */
  50. } FdInfo;
  51.  
  52. /*
  53.  * Flag values.
  54.  *
  55.  *    IS_A_DIRECTORY    This file is a directory.
  56.  *    FD_REFERENCED    This file is referenced by a directory.
  57.  *    FD_MODIFIED    This file descriptor has been modified.
  58.  *    FD_SEEN        This file descriptor has already been checked.
  59.  *    FD_ALLOCATED    This file descriptor is allocated.    
  60.  *    ON_MOD_LIST    This file descriptor is on the modified list.
  61.  *    FD_UNREADABLE    This file descriptor is in an unreadable sector.
  62.  *    FD_RELOCATE    This file descriptor is in a readable sector in
  63.  *            an unreadable block and is being relocated.
  64.  */
  65. #define    IS_A_DIRECTORY    0x01
  66. #define    FD_REFERENCED    0x02
  67. #define    FD_MODIFIED    0x04
  68. #define    FD_SEEN        0x08
  69. #define    FD_ALLOCATED    0x10
  70. #define    ON_MOD_LIST    0x20
  71. #define    FD_UNREADABLE    0x40
  72. #define    FD_RELOCATE    0x80
  73.  
  74. /*
  75.  * Structure for each element of the list of modified file descriptors.
  76.  */
  77. typedef struct ModListElement {
  78.     List_Links        links;
  79.     int            fdNum;
  80.     Fsdm_FileDescriptor    *fdPtr;
  81. } ModListElement;
  82. extern    List_Links    modListHdr;
  83. #define    modList &modListHdr
  84.  
  85. /*
  86.  * Structure for each element of the list of relocating file descriptors.
  87.  * Note that it looks like a ModListElement with an extra file descriptor
  88.  * number at the end.  It can be inserted into the modList and written
  89.  * in location newFdNum once newFdNum has been assigned.
  90.  */
  91. typedef struct RelocListElement {
  92.     List_Links        links;
  93.     int            newFdNum;
  94.     Fsdm_FileDescriptor    *fdPtr;
  95.     int            origFdNum;
  96. } RelocListElement;
  97. extern    List_Links    relocListHdr;
  98. #define    relocList &relocListHdr
  99.  
  100. typedef enum {
  101.     DIRECT, 
  102.     INDIRECT, 
  103.     DBL_INDIRECT
  104. } BlockIndexType;
  105.  
  106. typedef enum {
  107.     FD, 
  108.     BLOCK, 
  109. } ParentType;
  110.  
  111. /*
  112.  * Structure for each element of the list of file blocks that need to be copied.
  113.  */
  114.  
  115. typedef struct CopyListElement {
  116.     List_Links        links;
  117.     BlockIndexType    blockType;
  118.     short        fragments;
  119.     int            index;
  120.     ParentType        parentType;
  121.     int            parentNum;
  122.     Fsdm_FileDescriptor    *fdPtr;
  123. } CopyListElement;
  124.  
  125. extern    List_Links    copyListHdr;
  126. #define    copyList ©ListHdr
  127.  
  128.  
  129. /*
  130.  * Structure to contain the current state about a block index.
  131.  */
  132.  
  133.  
  134. typedef struct DirIndexInfo {
  135.     FdInfo         *fdInfoPtr;         /* Status info about the file 
  136.                           * descriptor being read. */
  137.     Fsdm_FileDescriptor *fdPtr;                  /* The file descriptor being
  138.                         read. */
  139.     BlockIndexType indexType;             /* Whether chasing direct, 
  140.                         indirect, or doubly indirect 
  141.                         blocks. */
  142.     int         blockNum;             /* Block that is being read, 
  143.                         written, or allocated. */
  144.     int         blockAddr;             /* Address of directory block
  145.                         to read. */
  146.     int         dirOffset;             /* Offset of the directory entry 
  147.                         that we are currently examining 
  148.                         in the directory. */
  149.     char     dirBlock[FS_BLOCK_SIZE];    /* Where directory data is 
  150.                         stored. */
  151.     int         numFrags;             /* Number of fragments stored in
  152.                         the directory entry. */
  153.     int         firstIndex;             /* An index into either the direct
  154.                             block pointers or into an 
  155.                             indirect block. */
  156.     int         secondIndex;             /* An index into a doubly indirect
  157.                             block. */
  158.     char      firstBlock[FS_BLOCK_SIZE];  /* First level indirect block. */
  159.     int         firstBlockNil;             /* The first level block is 
  160.                         empty.*/
  161.     char      secondBlock[FS_BLOCK_SIZE]; /* Second level indirect block. */
  162.     int         secondBlockNil;         /* The second level block 
  163.                         is empty.*/
  164.     int         dirDirty;             /* 1 if the directory block is
  165.                         dirty. */
  166. } DirIndexInfo;
  167.  
  168. extern int    numBlocks;
  169. extern int    numFiles;
  170. extern int    numBadDesc;
  171. extern int    numFrags;
  172. extern int    foundError;
  173. extern int    errorType;
  174. extern int    fdBitmapError;
  175. extern Boolean    tooBig;
  176. extern int    noCopy;
  177. extern int    debug;
  178. extern char    end[];
  179. extern FILE     *outputFile;
  180. extern int    patchHeader;
  181. extern int    writeDisk;
  182. extern int    verbose;
  183. extern int    silent;
  184. extern int    clearDomainNumber;
  185. extern int    recoveryCheck;
  186. extern int    badBlockInit;
  187. extern int    patchRoot;
  188. extern int    flushBuffer;
  189. extern int    maxHeapSize;
  190. extern int    bufferSize;
  191. extern int    heapSize;
  192. extern int    lastErrorFD;
  193. extern int    num1KBlocks;
  194. extern int    bytesPerCylinder;
  195. extern List_Links    modListHdr;
  196. extern List_Links    relocListHdr;
  197. extern unsigned char *fdBitmapPtr;
  198. extern unsigned char *cylBitmapPtr;
  199. extern unsigned char bitmasks[];
  200. extern int    rawOutput;
  201. extern int    attached;
  202. extern int    outputFileNum;
  203. extern char    *outputFileName;
  204. extern Ofs_DomainHeader  *domainPtr;
  205. extern int        partFID;
  206. extern int    bitmapVerbose;
  207. extern int    fixCount;
  208. extern int    numReboot;
  209. extern int    clearFixCount;
  210. extern int    blockToFind;
  211. extern int    fileToPrint;
  212. extern int    setCheckedBit;
  213.  
  214. extern int Output();    
  215. extern void OutputPerror();    
  216. extern void WriteOutputFile();    
  217. extern int CloseOutputFile();    
  218. extern void ExitHandler();
  219. extern char *sbrk();
  220. extern void ClearFd();
  221. extern void UnmarkBitmap();
  222. extern int MarkBitmap();
  223. extern void AddToCopyList();
  224.  
  225. /*
  226.  * Macro to get a pointer into the bit map for a particular block.
  227.  */
  228. #define BlockToCylinder(domainPtr, blockNum) \
  229.     (blockNum) / (domainPtr)->geometry.blocksPerCylinder
  230.  
  231. #define GetBitmapPtr(domainPtr, bitmapPtr, blockNum) \
  232.   &((bitmapPtr)[BlockToCylinder(domainPtr, blockNum) * \
  233.   bytesPerCylinder + (blockNum) % (domainPtr)->geometry.blocksPerCylinder / 2])
  234.  
  235. /*
  236.  * Macros to convirt physical block numbers to virtual block numbers. All direct
  237.  * blocks are virtual, indirect blocks are physical.
  238.  */
  239. #define VirtToPhys(domainPtr,blockNum) \
  240.     ((blockNum) + (domainPtr)->dataOffset * FS_FRAGMENTS_PER_BLOCK)
  241.  
  242. #define PhysToVirt(domainPtr,blockNum) \
  243.     ((blockNum) - (domainPtr)->dataOffset * FS_FRAGMENTS_PER_BLOCK)
  244.  
  245. #define MarkFDBitmap(num,bitmapPtr) \
  246.     (bitmapPtr)[(num) >> 3] |= (1 << (7 -((num)  & 7))) 
  247.  
  248. #define UnmarkFDBitmap(num,bitmapPtr) \
  249.     (bitmapPtr)[(num) >> 3] &= ~(1 << (7 -((num)  & 7))) 
  250.  
  251. /*
  252.  * Number of file descriptors in a sector, if we have to go through
  253.  * the sectors individually.
  254.  */
  255. #define FILE_DESC_PER_SECTOR (FSDM_FILE_DESC_PER_BLOCK / DISK_SECTORS_PER_BLOCK)
  256.  
  257.  
  258.  
  259. #define Alloc(ptr,type,number) AllocByte((ptr),type,sizeof(type) * (number))
  260.  
  261. #define AllocByte(ptr,type,numBytes) { \
  262.     int oldHeapSize = heapSize; \
  263.     (ptr) = (type *) malloc((unsigned) (numBytes)); \
  264.     heapSize = (int) (sbrk(0) - (char *) end); \
  265.     if ((heapSize != oldHeapSize) && (debug)) {\
  266.         Output(stderr,"Heapsize now %d.\n",heapSize); \
  267.     }\
  268.     if ((maxHeapSize > 0) && (heapSize > maxHeapSize) && (!tooBig)) { \
  269.         tooBig = TRUE; \
  270.         Output(stderr,"Heap limit exceeded.\n"); \
  271.         (ptr) = NULL; \
  272.         foundError = 1;\
  273.         errorType = EXIT_OUT_OF_MEMORY;\
  274.     } }
  275.  
  276. #define min(a,b) (((a) < (b)) ? (a) : (b) )
  277.  
  278. #endif _FSCHECK
  279.